import time

from common.base_page import BasePage
from selenium.webdriver.common.by import By
from page_object.login.login_locators import LoginLocator as loc

class LoginPage(BasePage):
    # url ='https://hro.workai.com.cn/'
    # username = (By.NAME,'username')
    # pwd = (By.NAME,'password')
    # button = (By.XPATH,'//*[@id="root"]/div/div/div/div[2]/div/div/div/button')
    def login(self,text,pwd):

        # self.open()
        # self.wait_visibility_ele(self.button,loc_desc='等待登录按钮加载出来。。。')
        # time.sleep(2)
        # self.input(self.username,text,loc_desc='证号框')
        # time.sleep(2)
        # self.input(self.pwd,pwd,loc_desc='密码框')
        # time.sleep(2)
        # self.click(self.button,loc_desc='登录按钮')
        self.wait_visibility_ele(loc.button,loc_desc='等待登录按钮加载出来。。。')
        time.sleep(2)
        self.locter(loc.username,loc_desc='清空账号框').clear()
        time.sleep(1)
        self.input(loc.username,text,loc_desc='证号框')
        time.sleep(2)
        self.locter(loc.pwd, loc_desc='清空密码框').clear()
        time.sleep(1)
        self.input(loc.pwd,pwd,loc_desc='密码框')
        time.sleep(2)
        # self.click(loc.button, loc_desc='登录按钮')
        # time.sleep(2)

    def login_err(self):
        time.sleep(2)

        self.click(loc.button, loc_desc='登录按钮')
        # self.driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[2]/div/div/div/button').click()
        time.sleep(2)
        return self.get_element_text(loc.err_msg,loc_desc="获取用户/密码不正确的文本")

    def login_account_err(self):
        return self.get_element_text(loc.account_err,loc_desc='获取 账号失败的文本')

    def login_success(self):
        # time.sleep(2)
        # self.driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div[2]/div/div/div/button').click()


        # self.click(loc.button, loc_desc='登录按钮')
        time.sleep(5)
        return self.get_element_text(loc.account_text,loc_desc='获取登录成功后用户的昵称')

    def login1(self,text,pwd):

        # self.open()
        # self.wait_visibility_ele(self.button,loc_desc='等待登录按钮加载出来。。。')
        # time.sleep(2)
        # self.input(self.username,text,loc_desc='证号框')
        # time.sleep(2)
        # self.input(self.pwd,pwd,loc_desc='密码框')
        # time.sleep(2)
        # self.click(self.button,loc_desc='登录按钮')
        self.wait_visibility_ele(loc.button,loc_desc='等待登录按钮加载出来。。。')
        time.sleep(2)
        self.locter(loc.username,loc_desc='清空账号框').clear()
        time.sleep(1)
        self.input(loc.username,text,loc_desc='证号框')
        time.sleep(2)
        self.locter(loc.pwd, loc_desc='清空密码框').clear()
        time.sleep(1)
        self.input(loc.pwd,pwd,loc_desc='密码框')
        time.sleep(2)
        self.click(loc.button, loc_desc='登录按钮')
        time.sleep(2)
# //*[@id="root"]/div/div/div/div[2]/div/div/div/div[1]/div[2]/div[1]/div/div[3]/div/div/div
# /html/body/div/div/span/div/div/div/span/
# //*[@id="root"]/div/div/div/div[2]/div/div/div/div[1]/div[2]/div[1]/div/div[3]/div/div/div

# //*[@id="root"]/div/div/div/div[2]/div/div/div/div[1]/div[2]/div[1]/div/div[2]/div/div/div
# if __name__ == '__main__':
#     options = webdriver.ChromeOptions()
#     options.binary_location = "E:\Chrome\Chrome\App\Google Chrome.exe"  # chrome 不是安装在C盘
#     driver = webdriver.Chrome(options=options)
#     text = 'dsds'
#     pwd = '122445545450'
#     lp = LoginPage(driver)
#     lp.login(text, pwd)


#  用户/密码不正确